package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Sceneryspot;
import com.ruoyi.system.service.ISceneryspotService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 景点Controller
 * 
 * @author ruoyi
 * @date 2020-10-15
 */
@Controller
@RequestMapping("/system/sceneryspot")
public class SceneryspotController extends BaseController
{
    private String prefix = "system/sceneryspot";

    @Autowired
    private ISceneryspotService sceneryspotService;

    @RequiresPermissions("system:sceneryspot:view")
    @GetMapping()
    public String sceneryspot()
    {
        return prefix + "/sceneryspot";
    }

    /**
     * 查询景点列表
     */
    @RequiresPermissions("system:sceneryspot:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Sceneryspot sceneryspot)
    {
        startPage();
        List<Sceneryspot> list = sceneryspotService.selectSceneryspotList(sceneryspot);
        return getDataTable(list);
    }

    /**
     * 导出景点列表
     */
    @RequiresPermissions("system:sceneryspot:export")
    @Log(title = "景点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Sceneryspot sceneryspot)
    {
        List<Sceneryspot> list = sceneryspotService.selectSceneryspotList(sceneryspot);
        ExcelUtil<Sceneryspot> util = new ExcelUtil<Sceneryspot>(Sceneryspot.class);
        return util.exportExcel(list, "sceneryspot");
    }

    /**
     * 新增景点
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存景点
     */
    @RequiresPermissions("system:sceneryspot:add")
    @Log(title = "景点", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Sceneryspot sceneryspot)
    {
        return toAjax(sceneryspotService.insertSceneryspot(sceneryspot));
    }

    /**
     * 修改景点
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Sceneryspot sceneryspot = sceneryspotService.selectSceneryspotById(id);
        mmap.put("sceneryspot", sceneryspot);
        return prefix + "/edit";
    }

    /**
     * 修改保存景点
     */
    @RequiresPermissions("system:sceneryspot:edit")
    @Log(title = "景点", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Sceneryspot sceneryspot)
    {
        return toAjax(sceneryspotService.updateSceneryspot(sceneryspot));
    }

    /**
     * 删除景点
     */
    @RequiresPermissions("system:sceneryspot:remove")
    @Log(title = "景点", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sceneryspotService.deleteSceneryspotByIds(ids));
    }
}
